<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta http-equiv="Expires" content="0">
  <meta http-equiv="Pragma" content="no-cache">
  <meta http-equiv="Cache-control" content="no-cache">
  <meta http-equiv="Cache" content="no-cache">
  <title>客服</title>
  <!--<script src="https://res.wx.qq.com/mmbizwap/zh_CN/htmledition/js/vconsole/3.0.0/vconsole.min.js"></script>-->
  <!--<script>-->
    <!--var vConsole = new VConsole();-->
  <!--</script>-->
  <link href="./static/service/js/layui/css/layui.mobile.css" rel="stylesheet"/>
  <link href="./static/service/js/layui/css/modules/layim/mobile/layim.css" rel="stylesheet"/>
  <link rel="stylesheet" href="./static/service/css/toast.css">
  <style>
    .phone_gdt {
      -webkit-overflow-scrolling: touch;
      -webkit-transition: width 0.3s ease;
      -moz-transition: width 0.3s ease;
      -ms-transition: width 0.3s ease;
      -o-transition: width 0.3s ease;
      transition: width 0.3s ease;
    }
  </style>
</head>
<body>
  <div class="layim-panel layui-m-anim-left">
    <div class="layim-title" style="background-color: #36373C;">
      <p><i class="layui-icon layim-chat-back" onclick="loginOut()">&#xe603;</i> <span id="title">客服</span></p>
    </div>
    <div class="layui-unselect layim-content">
      <div class="layim-chat layim-chat-friend">
        <div class="layim-chat-main">
          <ul id="chat-list" class="phone_gdt">

          </ul>
        </div>
        <div class="layim-chat-footer">
          <div class="layim-chat-send">
            <input type="text" autocomplete="off" id="msg"/>
            <button class="layim-send layui-disabled" id="send">发送</button>
          </div>
          <div class="layim-chat-tool">
            <span class="layui-icon layim-tool-face" title="选择表情" id="up-face">&#xe60c;</span>
            <span class="layui-icon layim-tool-image" title="上传图片" id="up-image">&#xe60d;</span>
            <span class="layui-icon layim-tool-video" title="上传视频" id="up-video">&#xe6ed;</span>
            <span class="layui-icon layim-tool-favorite" title="我的收藏" id="up-favorite">&#xe600;</span>
            <!--<span class="layui-icon layim-tool-image" title="发送文件"></span>-->
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="layui-m-layerchild layim-layer layui-m-anim-scale">
    <div class="layui-m-layercont" style="display:none;padding:0" id="face-box">

    </div>
    <div class="layui-m-layercont" style="display:none;padding:0" id="favorite-box">
      <ul class="layui-layim-face" id="favorite-box-ul" style="padding: 0">
      </ul>
    </div>
  </div>
  <!--<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>-->
  <script src="./static/service/js/jquery-1.9.0.min.js"></script>
  <script src="./static/service/js/jquery.cookie.js"></script>
  <script src="./static/service/js/reconnecting-websocket.js"></script>
  <script src="./static/service/js/toast.js"></script>
  <script>
    var deviceType = getDeviceType()
    var config = {
      uid: getQueryString('id') || '',
      name: getQueryString('name') || '',
      avatar: getQueryString('avatar') || '',
      group: '1',
      socket: getQueryString('socket'),
      shopSite: getQueryString('shopSite'),
      chatSite: getQueryString('chatSite'),
      goods_commonid: getQueryString('goods_commonid') || ''
    }

    function getQueryString(name) {
      var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
      var r = window.location.search.substr(1).match(reg)
      if (r != null) {
        return decodeURIComponent(r[2])
      }
      return null
    }

    var versionUrl = config.shopSite + '/mobile/index.php?act=login&op=getAppVersionInfo'
    try {
      setInterval(function () {
        var version = window.localStorage.getItem('version')

        $.post(versionUrl, {}, function (response) {
          var data = JSON.parse(response)
          if (parseFloat(data.data.app_version) > parseFloat(version || 0)) {
            window.localStorage.setItem('version', data.data.app_version)
            if (deviceType == 'wx-Android') {
              window.location.href = updateUrl(window.location.href)
            } else {
              window.location.reload(true)
            }
          }
        });
      }, 10000)
    }
    catch (e) {
      console.log('处理版本号发生异常', e)
    }

    var key = window.localStorage.getItem('key')
    window.addFavorite = function(url) {
      var hostUrl = config.chatSite
      url = url.replace(hostUrl, '')
      $.post(config.chatSite + '/index/Favorite/addFavorite', {key: key, content: url}, function (response) {
        console.log('sss')
        bw.toast('收藏成功')
      });
    }

    function getDeviceType() {
      var agent = navigator.userAgent
      var device = ''
      if (agent.indexOf('MicroMessenger') !== -1 && agent.indexOf('Android') !== -1) {
        device = 'wx-Android'
      } else if (agent.indexOf('MicroMessenger') !== -1 && agent.indexOf('iPhone') !== -1) {
        device = 'wx-iPhone'
      } else if (agent.indexOf('APICloud') !== -1) {
        device = 'APICloud'
      } else if (agent.indexOf('Android') !== -1) {
        device = 'Android'
      } else if (agent.indexOf('iPhone') !== -1) {
        device = 'iPhone'
      } else if (agent.indexOf('iPad') !== -1) {
        device = 'iPad'
      } else if (agent.indexOf('Windows') !== -1) {
        device = 'Windows'
      } else {
        device = 'unknown'
      }
      return device
    }

    function updateUrl(url, keyValue) {
      var key = (keyValue || 't') + '=' // 默认是“t”
      var reg = new RegExp(key + '\\d+') // 正则：t=1472286066028
      var timestamp = +new Date()
      if (url.indexOf(key) > -1) { // 有时间戳，直接更新
        return url.replace(reg, key + timestamp)
      } else { // 没有时间戳，加上时间戳
        if (url.indexOf('?') > -1) {
          var urlArr = url.split('?')
          if (urlArr[1]) {
            return urlArr[0] + '?' + key + timestamp + '&' + urlArr[1]
          } else {
            return urlArr[0] + '?' + key + timestamp
          }
        } else {
          if (url.indexOf('#') > -1) {
            return url.split('#')[0] + '?' + key + timestamp + window.location.hash
          } else {
            return url + '?' + key + timestamp
          }
        }
      }
    }
  </script>
  <script src="./static/service/js/layui/layui.js"></script>
  <script src="./static/service/js/functions.js"></script>
  <script src="./static/customer/js/whisper-mobile.js"></script>
</body>
</html>